import { SET_ROUTEKEY } from "../types/index";
export default {
  namespaced: true,
  state: {
    keepLiveRoute: [], //缓存的路由
    routeKey: null,
    routeShow: true,
  },
  mutations: {
    PUSH_KEEPLIVE(state, component) {
      if (!state.keepLiveRoute.includes(component)) {
        state.keepLiveRoute.push(component);
      }
    },
    REMOVE_KEEPLVE(state, component) {
      var index = state.keepLiveRoute.indexOf(component);
      if (index !== -1) {
        state.keepLiveRoute.splice(index, 1);
      }
    },
    CLEAR_KEEPLIVE(state) {
      state.keepLiveRoute = [];
    },
    SET_ROUTEKEY(state, key) {
      state.routeKey = key;
    },
    SET_ROUTESHOW(state, key) {
      state.routeShow = key;
    },
  },
  actions: {
    setRouteKey({ commit }, key) {
      commit(SET_ROUTEKEY, key);
    },
  },
};
